//
//  MLWTipsICookMaterialCell.m
//  KITCHEN_STORIES
//
//  Created by 孟令通 on 16/6/13.
//  Copyright © 2016年 MLW. All rights reserved.
//

#import "MLWTipsICookMaterialCell.h"

#import "MLWTipsICookMaterialModel.h"

#import "MLWTipsICookMaterialDetailModel.h"

#import "MLWBaseView.h"

@implementation MLWTipsICookMaterialCell

-(void)getHeithgWithNumber:(NSInteger)number PageHeight:(PageHeight)pageHeight
{
    pageHeight(number);
}

-(id)initWithIdentifier:(NSString *)identifier
{
    self = [super initWithIdentifier:identifier];
    
    if (self) {
        
        self.materialArray = [NSArray array];
        self.identifier = identifier;
    }
    
    return self;
}

-(void)setMaterialArray:(NSArray *)materialArray
{
    
    if (_materialArray != materialArray) {
        
        [_materialArray release];
        
        _materialArray = [materialArray retain];
        
        MLWTipsICookMaterialModel *model = [_materialArray firstObject];
        
        UIImageView *mainImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 300)];
        
        [mainImage sd_setImageWithURL:[NSURL URLWithString:model.material_image] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        
        [self addSubview:mainImage];
        [mainImage release];
        
        NSInteger i = 1;
        
        for (MLWTipsICookMaterialDetailModel *detailModel in model .materialDetailModelArray) {
            
            UIView *labelView = [[UIView alloc] initWithFrame:CGRectMake(15, (30 + 6) * i + 305, ScreenWidth - 30, 30)];
            
            UILabel *materialName = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, (ScreenWidth - 30) / 2.0, 30)];
            
            materialName.text = detailModel.material_name;
            [materialName setFont:[UIFont systemFontOfSize:14]];
            
            [labelView addSubview:materialName];
            [materialName release];
            
            UILabel *materialWeight = [[UILabel alloc] initWithFrame:CGRectMake((ScreenWidth - 30) / 2.0, 0, (ScreenWidth - 30) / 2.0, 30)];
            
            materialWeight.text = detailModel.material_weight;
            [materialWeight setFont:[UIFont systemFontOfSize:14]];
            
            [labelView addSubview:materialWeight];
            [materialWeight release];
            
            if (i % 2 != 0) {
                
                labelView.backgroundColor = [UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:1.00];
                
            }
            
            [self addSubview:labelView];
            [labelView release];
            
            i += 1;
            
        }
        
    }
    
}

@end
